tuple1 = (1, 2, 3, True, 'hello')
print(tuple1)
print(type(tuple1))

tuple2 = (1,)  # 只有一个元素时，加个 逗号，表明元组
print(tuple2)
print(type(tuple2))  # <class 'tuple'>

tuple3 = ()
print(tuple3)
print(type(tuple3))

tuple4 = tuple()
print(tuple4)
print(type(tuple4))

tuple5 = tuple('hello')  # str --> tuple
print(tuple5)  # ('h', 'e', 'l', 'l', 'o')
print(type(tuple5))

tuple6 = tuple([1, 2, 3, 4, 5])  # list --> tuple
print(tuple6)
print(type(tuple6))

list1 = list(tuple6)  # tuple --> list
print(list1)
print(type(list1))

str1 = str(tuple6)  # tuple --> str
print(str1)
print(type(str1))
print(str1[1])


print("=="*10)

# 序列的通用操作
tuple1 = (1, 2, 3, True, 'hello')
tuple6 = tuple([1, 2, 3, 4, 5])
# 索引
print("索引1：",tuple1[1])  # 2
print("索引-1：",tuple1[-1])  # hello
# 切片
print("切片：",tuple1[::-1])  #  ('hello', True, 3, 2, 1)
# len、amx
print("len ",len(tuple1))  # len  5
print("max,min: ",max(tuple6),min(tuple6))   # max,min:  5 1
# del 删除元组
del tuple5
# +
print("+: ",tuple1 + tuple6)  # (1, 2, 3, True, 'hello', 1, 2, 3, 4, 5)
# *
print("*: ",tuple1 * 2)  # (1, 2, 3, True, 'hello', 1, 2, 3, True, 'hello')
# in
print(2 in tuple1)  # True

print("***"*10)

# 元组的常用方法
tuple1 = (1, 2, 3, True, 'hello')
c = tuple1.count("hello")
print(c)
# 查找元素索引值
a = tuple1.index(2)
print(a)

print("***"*10)

# 遍历
for i in tuple1:
    print(i)

for index,val in enumerate(tuple1):
    print(index,val)

for i in range(len(tuple1)):
    print(i,tuple1[i])